<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #canvas {
      border: 1px solid #333;
    }
  </style>
</head>

<body>
  <canvas id="canvas" width="200" height="200"></canvas>
  <script>
    let canvas = document.getElementById("canvas");
    let ctx = canvas.getContext("2d");
    let radius = 60;
    let increase = true;
    /* 60~100 */
    function draw() {
      /* 清除画布 */
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      /* 绘制圆形  第一圆动画 */
      ctx.beginPath();
      ctx.arc(100, 100, radius, 0, Math.PI * 2);
      ctx.closePath();
      ctx.fillStyle = "#ff2d51";
      ctx.fill();
      /* 第二个圆 */
      ctx.beginPath();
      ctx.arc(100, 100, 50, 0, Math.PI * 2);
      ctx.closePath();
      ctx.fillStyle = "blue";
      ctx.fill();
      if (radius > 80) {
        increase = false;
      } else if (radius < 60) {
        increase = true;
      }
      if (increase) {
        radius++;
      } else {
        radius--;
      }
      setTimeout(draw, 50)
    }
    draw();
  </script>
</body>

</html>